package com.example.imoocmusicdemo.utils;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.widget.Toast;

import com.blankj.utilcode.util.RegexUtils;
import com.example.imoocmusicdemo.R;
import com.example.imoocmusicdemo.activity.LoginActivity;

public class UserUtil {
    /**
     * 验证用户输入的合法性
     */
    public static boolean validateLogin(Context context,String phone,String password){
       if (!RegexUtils.isMobileExact(phone)){
           Toast.makeText(context,"无效的手机号",Toast.LENGTH_SHORT).show();
           return false;
       }
        if (TextUtils.isEmpty(password)){
            Toast.makeText(context,"请输入密码",Toast.LENGTH_SHORT).show();
            return false;
        }
        return true;
    }
    /**
     * 退出登录
     */
    public static void logout(Context context){
        Intent intent=new Intent(context, LoginActivity.class);
        //添加intent标识符，清理task栈，并且新生成一个task栈
        //intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
        //定义Activity跳转动画
        //((Activity)context).overridePendingTransition(R.anim.open_enter, R.anim.close_enter);
    }
}
